#include <typedef.h>
//
#include <connector.hpp>
#include <console.hpp>
#include <logger.hpp>
#include <protocol.hpp>
#include <settings.hpp>
#include <udp_sender.hpp>

void signal_handler(int signo)
{
	if (signo == SIGINT)
	{
		LOGE("Ctl+C exit!\n");

		Logger::Instance()->Save();
		usleep(200 * 1000);

		rl_cleanup_after_signal();
		usleep(100 * 1000);
		exit(0);
	}
}

int main(int argc, char** argv)
{
	signal(SIGFPE, logger_dump_errors);
	signal(SIGSEGV, logger_dump_errors);
	signal(SIGTRAP, logger_dump_errors);
	signal(SIGABRT, signal_handler);
	signal(SIGINT, signal_handler);
	signal(SIGPIPE, signal_handler);

	Settings::Instance()->Start();
	Logger::Instance()->Start();
	Console::Instance()->Start();

	// UdpSender udp("192.168.43.85", 23011);
	// char* m_BuffSend = (char*)malloc(BUFF_FIFO_SIZE);

	// uint16_t m_DataTypeSend = P_TYPE_HEART;
	// uint16_t m_DataSeqSend	= 0;
	// int m_SizeSend			= 0;
	// uint16_t heart			= 0;
	// int size				= 2;
	// Protocol protocol;
	// protocol.Pack(m_BuffSend, &m_SizeSend, (char*)&heart, size, m_DataSeqSend, m_DataTypeSend);

	while (1)
	{
		// udp.SendData(m_BuffSend, m_SizeSend);
		usleep(100 * 1000);
	}

	return 0;
}
